package com.bionic.banking.logic.controller;

import com.bionic.banking.core.entity.Address;
import com.bionic.banking.dao.IAddressDao;
import com.bionic.banking.dao.classes.AddressDaoImpl;
import com.bionic.banking.logic.IAddressController;
import com.bionic.banking.logic.exception.InvalidParameterException;
import com.bionic.banking.logic.exception.TransactionTypeNotFoundException;

public class AddressController extends AbstractBean<Address> implements IAddressController {

    @Override
    protected IAddressDao getDaoObject() {
        return new AddressDaoImpl();
    }

    public AddressController() throws InstantiationException, IllegalAccessException {
        super();
    }

    @Override
    public Address createAddress(
            String country,
            String state,
            String region,
            String city,
            String street,
            String postalcode,
            String addressline1, String addressline2)
            throws TransactionTypeNotFoundException, InvalidParameterException {
        if (street == null) {
            throw new InvalidParameterException("null street");
        }
        if (city == null) {
            throw new InvalidParameterException("null city");
        }
        if (state == null) {
            throw new InvalidParameterException("null state");
        }
        Address address = new Address();
        address.setPostalCode(postalcode);
        address.setCountry(country);
        address.setRegion(region);
        address.setCity(city);
        address.setStreet(street);
        address.setLine1(addressline1);
        address.setLine2(addressline2);
        return address;
    }
}
